package com.cpp.server.controller;

import com.cpp.common.constant.ModuleConstant;
import com.cpp.common.result.Result;
import com.cpp.pojo.vo.view.OptimizeCourseVO;
import com.cpp.pojo.vo.view.StudentLearningEffectVO;
import com.cpp.pojo.vo.user.UserDataVO;
import com.cpp.pojo.vo.user.UserUseDataVO;
import com.cpp.server.aspect.annotation.MyLog;
import com.cpp.server.service.AdminViewService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/view")
@MyLog(module = ModuleConstant.OTHERS)
public class AdminViewContoller {
    private final AdminViewService adminViewService;

    //教师使用次数统计/活跃板块(当日/本周)
    //学生使用次数统计/活跃板块(当日/本周)

    //教师当日使用次数统计
    //加上redis缓存2分钟

    @GetMapping("/teacherDayUseData")
    public Result<UserUseDataVO> teacherDayUseData() {
        UserUseDataVO teacherUseData = adminViewService.teacherDayUseData();
        return Result.success(teacherUseData);
    }
    //学生当日使用次数统计
    @GetMapping("/studentDayUseData")
    public Result<UserUseDataVO> studentDayUseData() {
        UserUseDataVO studentUseData = adminViewService.studentDayUseData();
        return Result.success(studentUseData);
    }
    //教师本周使用次数统计
    @GetMapping("/teacherWeekUseData")
    public Result<UserUseDataVO> teacherWeekUseData() {
        UserUseDataVO teacherUseDataVO = adminViewService.teacherWeekUseData();
        return Result.success(teacherUseDataVO);
    }
    //学生本周使用次数统计
    @GetMapping("/studentWeekUseData")
    public Result<UserUseDataVO> studentWeekUseData() {
        UserUseDataVO studentUseDataVO = adminViewService.studentWeekUseData();
        return Result.success(studentUseDataVO);
    }
    //教学效率指数(备课与修正耗时、（柱状图）
    @GetMapping("/chapterEfficiency")
        public Result<Map<String,Double> >chapterEfficiency() {
        Map<String,Double> teachingEffectVO = adminViewService.chapterEfficiency();
        return Result.success(teachingEffectVO);
    }
    //课后练习设计与修正耗时
    @GetMapping("/examEfficiency")
    public Result<Map<String,Double> >examEfficiency() {
        Map<String,Double> examEfficiency = adminViewService.examEfficiency();
        return Result.success(examEfficiency);
    }
    //分析课程可优化方向

    @GetMapping("/optimizeCourse")
    @Cacheable(value = "admin_view_cache", key = "#root.methodName", unless = "#result == null")
    public Result<OptimizeCourseVO> optimizeCourse() {
        OptimizeCourseVO optimizeCourse = adminViewService.optimizeCourse();
        return Result.success(optimizeCourse);
    }
    //学生学习效果
    @GetMapping("/studentLearningEffect")
    public Result<StudentLearningEffectVO> studentLearningEffect(@RequestParam(required = false) Long subjectId) {
        StudentLearningEffectVO studentLearningEffectVOs = adminViewService.studentLearningEffect(subjectId);
        return Result.success(studentLearningEffectVOs);
    }



}
